home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / frontend / flyPVS / opengl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-06  |  2.3 KB  |  105 lines

  1. #include "../../lib/Fly3D.h"
  2. #include "opengl.h"
  3.  
  4. HGLRC m_hRC;
  5.  
  6. unsigned char halftone[]=
  7. {
  8.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  9.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  10.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  11.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  12.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  13.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  14.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  15.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  16.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  17.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  18.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  19.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  20.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  21.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  22.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  23.     0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,
  24. };
  25.  
  26. int CreateView(HDC hdc)
  27. {
  28.     PIXELFORMATDESCRIPTOR pfd, *ppfd;
  29.     int pixelformat;
  30.  
  31.     ppfd = &pfd;
  32.     memset(ppfd,0,sizeof(PIXELFORMATDESCRIPTOR));
  33.  
  34.     ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
  35.     ppfd->nVersion = 1;
  36.     ppfd->dwFlags =    PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
  37.     ppfd->iPixelType = PFD_TYPE_RGBA;
  38.     ppfd->cColorBits = 0;
  39.     ppfd->cDepthBits = 0;
  40.     ppfd->cAccumBits = 0;
  41.     ppfd->cStencilBits = 0;
  42.  
  43.     pixelformat = ChoosePixelFormat(hdc, ppfd);
  44.  
  45.     if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE) 
  46.         return FALSE;
  47.  
  48.     m_hRC = wglCreateContext( hdc );
  49.  
  50.     wglMakeCurrent( hdc, m_hRC );
  51.  
  52.     return 1;
  53. }
  54.  
  55. void DeleteView()
  56. {
  57.     if (m_hRC==0)
  58.         return;
  59.  
  60.     wglMakeCurrent(NULL, NULL);
  61.     wglDeleteContext(m_hRC);
  62.     m_hRC=0;
  63. }
  64.  
  65. void ResizeView(int sx,int sy)
  66. {
  67.     if (m_hRC==0)
  68.         return;
  69.     glViewport(0, 0, sx, sy);
  70. }
  71.  
  72. void InitView()
  73. {
  74.     glShadeModel(GL_FLAT);
  75.  
  76.     glEnable(GL_CULL_FACE);
  77.     glCullFace(GL_BACK);
  78.  
  79.     glEnable(GL_DEPTH_TEST);
  80.     glDepthFunc(GL_LESS);
  81.     glDisable(GL_DITHER);
  82.     glDisable(GL_FOG);
  83.     glDisable(GL_BLEND);
  84.     glDisable(GL_TEXTURE_2D);
  85.  
  86.     glDisable(GL_LINE_SMOOTH);
  87.     glDisable(GL_POLYGON_SMOOTH);
  88.  
  89.     float f[4]={ 0,0,0,1 };
  90.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT,f);
  91.  
  92.     glClearColor( 1,1,1,1 );
  93.     glClearDepth( 1 );
  94.  
  95.     glDrawBuffer(GL_BACK_LEFT);
  96.     glReadBuffer(GL_BACK_LEFT);
  97.  
  98.     glMatrixMode( GL_PROJECTION );
  99.     glLoadIdentity();
  100.     gluPerspective( 90, 1, NEAR_PLANE, FAR_PLANE);
  101.     glMatrixMode( GL_MODELVIEW );
  102.  
  103.     glPolygonStipple(halftone);
  104. }
  105.